﻿using MediatR;
using Traceability.APP.Application.Command.Traceability;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Traceability
{
    /// <summary>
    /// 溯源基本信息的反填
    /// </summary>
    public class GetOneTraceabilityCommonHandle:IRequestHandler<GetOneTraceabilityCommon,APIResult<Traceability_Management>>
    {
        private readonly IBaseRepository<Traceability_Management> TracDal;

        public GetOneTraceabilityCommonHandle(IBaseRepository<Traceability_Management> tracDal)
        {
            TracDal = tracDal;
        }


        Task<APIResult<Traceability_Management>> IRequestHandler<GetOneTraceabilityCommon, APIResult<Traceability_Management>>.Handle(GetOneTraceabilityCommon request, CancellationToken cancellationToken)
        {
            APIResult<Traceability_Management> result = new APIResult<Traceability_Management>();
            var list = TracDal.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list;
            return Task.FromResult(result);
        }



    }
}
